package commands;

import indexes.BattingIndex;
import indexes.PlayerIDIndex;
import indexes.PlayerNameIndex;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import util.BattingDatabaseFile;
import util.DatabaseFile;
import util.PlayerLogger;

import main.PlayerDB;
/**
 * This command logs all data fields for the given playerId.
 * @author bfults (Brian Fults - 905084698)
 *
 */
public class ShowStatsForCommand extends Command
{
    /**
     * Typical constructor.
     * @param args
     */
    public ShowStatsForCommand(List<String> args)
    {
        super(args);
    }
    
    

    @Override
    /**
     * Arguments come in the form of an
     * alphanumeric playerId.
     */
    public boolean execute(
        PlayerIDIndex idIndex,
        PlayerNameIndex nameIndex,
        PlayerLogger logger,
        DatabaseFile database, BattingIndex battingIndex, BattingDatabaseFile battingDatabase ) throws IOException
    {
        logger.write(super.getDivider() + "\n");
        logger.write("Command: show_stats_for " + getArguments().get(0) + "\n\n");
        Long foundOffset = idIndex.get(getArguments().get(0));
        
        if (foundOffset != null)
        {
            logger.write("Record for " + getArguments().get(0) + " should be at offset " +
                foundOffset + "\n");
            logger.write(database.getPlayer(foundOffset).toString() + "\n");
        }
        else
        {
            logger.write("Id: " + getArguments().get(0) + "not found.\n");
        }
        return true;
    }
    
    


}
